package bio.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author Huhailong
 * @Description time server
 * @Date 2021/4/8.
 */
public class TimeServer {

    /**
     * 主方法
     * @param args params
     */
    public static void main(String[] args) {
        int port = 8080;
        try(ServerSocket serverSocket = new ServerSocket(port)){
            System.out.println("Time Server is start in port :"+port);
            Socket socket;
            while(true){
                socket = serverSocket.accept(); //阻塞监听用户接入
                System.out.println("新的接入："+socket.getInetAddress()+" "+socket.getPort());
                //用户接入后分配一个新的线程进行处理
                new Thread(new TimeServerHandler(socket)).start();
            }
        } catch (IOException e){
            e.printStackTrace();
        }
    }
}
